<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>6-03 旋转</title>
</head>
<body>
  <canvas id="c" width="600" height="600" style="border: 1px solid #ccc;"></canvas>

  <script>
    const context = document.getElementById('c')
    const ctx = context.getContext('2d')

    ctx.fillStyle = 'pink'
    ctx.fillRect(30, 30, 60, 60)

    // 清屏
    ctx.clearRect(0, 0, context.width, context.height)

    ctx.translate(60, -30) // 修改旋转中心
    ctx.rotate(45 * Math.PI / 180)
    ctx.fillRect(30, 30, 60, 60)
  </script>
</body>
</html>